//Page Object
import regeneratorRuntimer from '../../lib/runtime/runtime'
import { request } from '../../request/index.js'
import { scanCode, showToast } from "../../utils/asyncWx.js"
const utils = require("../../utils/utils.js")
Page({
    data: {
        swiperList: [
            { url: '../../icons/Administrator_page/swiper_one.jpg' },
            { url: '../../icons/Administrator_page/swiper_one.jpg' },
            { url: '../../icons/Administrator_page/swiper_one.jpg' }
        ],
        //船员图片
        user: [{
            url: "../../icons/Administrator_page/swiper_one.jpg"
        }]
    },
    // 扫码
    async scanCode() {
        const res = await scanCode()



        console.log(res)
            //     //表示扫码成功
        const index = res.result.lastIndexOf('=')
            // console.log(res.result.slice(0, index))
            // const number = res.result[index + 1, res.result.length - 1]
        console.log(res.result.slice(0, index))

        if (res.result.slice(0, index) == "https://ship.gzcskj.cn/permanent/code?id") {
            const index = res.result.lastIndexOf('=')
            const number = res.result.slice(index + 1, res.result.length)
            console.log(number)
                //判断是不是授权过，如果授权过就直接进到用户端,读取opneid信息
            if (wx.getStorageSync('openid')) {
                wx.redirectTo({ url: '/pages/user_page/index?id=' + number });
            } else {
                wx.redirectTo({ url: '/pages/authorization/index?id=' + number });
            }
        } else {
            await showToast({
                title: "请扫本船舶的二维码"
            })
        }
    },
    onShareAppMessage: function() {
        console.log(111)
    },
    onShareTimeline() {
        console.log(222)
    }
});